package com.quasar.hpatient.view.personal.setup;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;

import com.quasar.hpatient.R;
import com.quasar.hpatient.base.BaseActivity;
import com.quasar.hpatient.network.RetrofitConnection;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;

/**
 * 关于我们
 */
@EActivity(R.layout.activity_about)
public class AboutActivity extends BaseActivity {

    String url= RetrofitConnection.RoutineUrls+"index/about";

    @ViewById(R.id.main_toolbar)
    Toolbar main_toolbar;
    @ViewById(R.id.webView)
    WebView webView;
    @ViewById(R.id.progressBar)
    ProgressBar progressBar;

    @AfterViews
    void init(){
        initView();
        initData();
    }

    @Override
    protected void initView() {
        initToolbar();

        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptEnabled(true); //支持 js
        //webSettings.setPluginsEnabled(true); //支持插件
        webSettings.setUseWideViewPort(false); //将图片调整到适合 webview 的大小
        webSettings.setSupportZoom(true); //支持缩放
        webSettings.supportMultipleWindows(); //多窗口
        webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); //关闭 webview 中缓存
        webSettings.setAllowFileAccess(true); //设置可以访问文件
        webSettings.setNeedInitialFocus(true); //当 webview 调用 requestFocus 时为 webview 设置节点
        webSettings.setBuiltInZoomControls(true); //设置支持缩放
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true); //支持通过 JS 打开新窗口
        webSettings.setLoadWithOverviewMode(true); // 缩放至屏幕的大小
        webSettings.setLoadsImagesAutomatically(true); //支持自动加载图片

        initOnClik();
    }

    private void initOnClik() {
        // WebView........
        webView.setWebViewClient(new WebViewClient() {
            @Override
            //网页加载完成
            public void onPageFinished(WebView view, String url) {
                // TODO Auto-generated method stub
                progressBar.setVisibility(View.GONE);
                super.onPageFinished(view, url);
            }

            // 网页加载失败，重新加载
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                // TODO Auto-generated method stub
                webView.loadUrl(url);
                return super.shouldOverrideUrlLoading(view, url);
            }
        });
    }

    @Override
    protected void initData() {
        webView.loadUrl(url);
    }
}
